package ligne2vie.topos.server.bo;

import java.io.Serializable;
import java.util.Date;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;

/**
 * The class {@link ActionHistory} allows storing histories of actions into the database.
 * 
 * @author thuguerre
 * @since 1.0.0
 */
@PersistenceCapable(detachable = "true")
public class ActionHistory implements Serializable {

	/**
	 * Default serial UID.
	 */
	private static final long serialVersionUID = -3148195597516975340L;

	/**
	 * {@link ActionHistory}'s identifier;
	 */
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	protected Key id;

	/**
	 * The date when the action has been performed.
	 */
	@Persistent
	private Date creationDate;

	/**
	 * Type of action.
	 */
	@Persistent
	private ActionType action;

	/**
	 * Email of the user which has performed the action.
	 */
	@Persistent
	private String userEmail;

	public Date getCreationDate() {
		return creationDate;
	}

	public void setCreationDate(Date creationDate) {
		this.creationDate = creationDate;
	}

	public ActionType getAction() {
		return action;
	}

	public void setAction(ActionType action) {
		this.action = action;
	}

	public String getUserEmail() {
		return userEmail;
	}

	public void setUserEmail(String userEmail) {
		this.userEmail = userEmail;
	}

	/**
	 * Default constructor.
	 */
	public ActionHistory(Date creationDate, ActionType action, String userEmail) {
		super();
		this.creationDate = creationDate;
		this.action = action;
		this.userEmail = userEmail;
	}

	/**
	 * The enumeration {@link ActionType} defines all the possible actions for which storing history in database.
	 * 
	 * @author thuguerre
	 * @since 1.0.0
	 */
	public enum ActionType {

		SUMMIT_CREATE, SUMMIT_EDIT, SUMMIT_REMOVE;
	}
}
